package com.backend.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * @author wangzizh
 **/
public class NullStringJsonSerializer extends JsonSerializer<Object> {

  @Override
  public void serialize(Object o, JsonGenerator jsonGenerator,
      SerializerProvider serializerProvider) throws IOException {
    if (o == null) {
      jsonGenerator.writeString("");
    } else {
      jsonGenerator.writeObject(o);
    }
  }

}
